﻿using Unity.WebApi;
using SalesPages.WebApi.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Exceptionless;
using System.Net;

namespace SalesPages.WebApi
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Exceptionless.ExceptionlessClient.Default.RegisterWebApi(GlobalConfiguration.Configuration);


        }
        protected void Application_Error(object sender, EventArgs e)
        {
            var ex = Server.GetLastError();
            var httpStatusCode = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : 500;
            var httpContext = ((WebApiApplication)sender).Context;
            if (httpStatusCode == 404)
                ExceptionlessClient.Default.SubmitNotFound(Context.Request.RawUrl);
        }
    }
}
